package com.prp.gwt.client;

import com.google.gwt.user.client.rpc.StatusCodeException;
import com.prp.gwt.client.widgets.MessageDialogBox;

public class ClientUtility {

	public static void handleException(Throwable caught) {

		if (caught instanceof ClientException) {
			MessageDialogBox.show(((ClientException) caught).getTitle(), caught.getMessage());
		} else if (caught instanceof StatusCodeException) {
			if(((StatusCodeException) caught).getStatusCode() == 0)
				return;
			String text = "连接服务器错误.<br/>";
			text += "请稍后重试<br/>";
			text += "状态码:<br/>";
			text += ((StatusCodeException) caught).getStatusCode();
			MessageDialogBox.show("发生错误", text);
		} else {
			String text = "无法连接到服务器.<br/>";
			text += "请稍后重试<br/>";
			text += "错误信息:<br/>";
			text += caught.getMessage();
			MessageDialogBox.show("发生错误", text);
		}
	}
	
}
